//
//  BaseViewController.m
//  DaMaoMall
//
//  Created by HXHL-wally on 16/7/8.
//  Copyright © 2016年 daMao-wally. All rights reserved.
//

#import "BaseViewController.h"

// 导航栏 左侧按钮大小，ios7以上系统 aHeight = 20
#define LEFTBUTTONFRAME(aHeight) CGRectMake(0,0+aHeight,44,44)

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // Do any additional setup after loading the view.
    [self.navigationItem.backBarButtonItem setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:5]} forState:UIControlStateNormal];
    // 背景颜色 - 整个View的
    self.navigationController.navigationBar.hidden =YES;
    // 导航栏 View
    self.navigationBarView = [[UIView alloc] initWithFrame:CGRectMake(0,0,GetScreenWidth, UI_NAVIGATION_BAR_HEIGHT+UI_STATUS_BAR_HEIGHT)];
    //     导航栏 背景图 {0，0，View的宽，64}
    _navigationBarBg = [[UIImageView alloc] init];
    _navigationBarBg.frame = CGRectMake(0, 0, GetScreenWidth, UI_NAVIGATION_BAR_HEIGHT+UI_STATUS_BAR_HEIGHT);
    _navigationBarBg.backgroundColor = BGCOLOR;
    self.navigationBarBg.image = [UIImage imageNamed:@"bg-head"];
    [_navigationBarView addSubview:_navigationBarBg];
    [self.view addSubview:_navigationBarView];
    
    // 导航栏中间 title
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, UI_STATUS_BAR_HEIGHT, GetScreenWidth-120, UI_NAVIGATION_BAR_HEIGHT)];
//    _titleLabel.backgroundColor = [UIColor clearColor];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.textColor = UIColorFromRGB(0xffffff);
    _titleLabel.font = [UIFont systemFontOfSize:19.0f];
//    _titleLabel.font = [UIFont fontWithName:@"Helvetica Bold" size:17.0f];
    [_navigationBarBg addSubview:_titleLabel];
    
    // 创建 左侧 按钮
    [self createLeftBtn];
    
    // 创建 右侧 按钮
    [self createRightButton];
    
    // 视图大小 以及 背景
    self.contentView= [[UIView alloc] initWithFrame:CGRectMake(0, height_y(_navigationBarView), GetScreenWidth, UI_MAINSCREEN_HEIGHT-UI_NAVIGATION_BAR_HEIGHT)];
    self.contentView.backgroundColor = mApp_Bg_Color;
    
    
    [self.view addSubview:_contentView];
    
}

#pragma mark - 创建 左侧 按钮
- (void)createLeftBtn
{
    // 模拟酷狗效果
    self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //    self.leftBtn.glowsWhenHighlighted = NO;
    //    self.leftBtn.highlightedGlowColor = [UIColor whiteColor];
    // 项目都是ios7以上版本，故写死
    _leftBtn.frame = CGRectMake(20, 32, 10, 20);
    [_leftBtn setBackgroundImage:[UIImage imageNamed:@"icon-back"] forState:UIControlStateNormal];
    [_leftBtn addTarget:self action:@selector(backPrePage) forControlEvents:UIControlEventTouchUpInside];
    _leftBtn.adjustsImageWhenHighlighted =NO;
    [_navigationBarView addSubview:_leftBtn];
}
#pragma mark - 返回上个页面
- (void)backPrePage
{
    [self.navigationController popViewControllerAnimated:YES];
    
    DMLog(@"self.navigationController ====== %lud",self.navigationController.viewControllers.count);
}

#pragma mark - 创建 右侧 按钮
- (void)createRightButton
{
    self.rightBtn= [UIButton buttonWithType:UIButtonTypeCustom];
    self.rightBtn.frame = CGRectMake(GetScreenWidth-50, 20, 44, 44);
    [self.navigationBarView addSubview:self.rightBtn];
}


// 当隐藏Bar时当前页面frame改变
-(void)changFrameWhenHiddenNavgationBar
{
//    self.navigationBarView.hidden=YES;
    // 一下View为电池栏的 View
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, GetScreenWidth, UI_STATUS_BAR_HEIGHT)]; // 高度20
    view.backgroundColor  = [UIColor colorWithPatternImage:[UIImage imageNamed:STATUSBARBG]];
    //    view.backgroundColor = [UIColor blackColor];
    [self.view addSubview:view];
    // frame 为 {0，20，UI_SCREEN_WIDTH，(UI_SCREEN_HEIGHT-20}
    _contentView.frame= CGRectMake(0,height_y(view),GetScreenWidth, UI_MAINSCREEN_HEIGHT);
}

@end

#pragma mark - 快速创建控件
@implementation UIViewController (Create_UI_Method)
UITextField *creatGHTextField(NSString *placeTitle,CGRect frame){
    UITextField *textField=[[UITextField alloc]initWithFrame:frame];
    textField.placeholder =placeTitle;
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.clearsOnBeginEditing =YES;
    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    return textField;
}

UIButton *creatGHButton(CGRect frame,NSString *title,UIImage*normalImage,UIImage *hightImage){
    UIButton *bnt=[UIButton buttonWithType:UIButtonTypeCustom];
    [bnt setFrame:frame];
    [bnt setTitle:title forState:UIControlStateNormal];
    bnt.titleLabel.text =title;
    [bnt setBackgroundImage:normalImage forState:UIControlStateNormal];
    [bnt setBackgroundImage:hightImage forState:UIControlStateHighlighted];
    [bnt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    return bnt;
}

UILabel *creatGHLable(NSString *name ,CGRect frame){
    UILabel *lable=[[UILabel alloc]initWithFrame:frame];
    [lable setText:name];
    lable.backgroundColor=[UIColor clearColor];
    lable.lineBreakMode=NSLineBreakByWordWrapping;
    lable.numberOfLines= 0;
    lable.textAlignment=NSTextAlignmentCenter;
    lable.font=[UIFont systemFontOfSize:15.5];
    lable.textColor = goodcolor;
    
    
    return lable;
}
UIImageView *creatGHImageView(CGRect frame,UIImage *image){
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:frame];
    imageView.backgroundColor=[UIColor clearColor];
    imageView.userInteractionEnabled =YES;
    imageView.image=image;
    return imageView;
}

@end